$(function () {
  var Uid = getQueryStr("id");
  $.ajax({
    type: "post",
    url:"/dingding-web/userMallAction!getMallIndex.action",
    dataType: "jsonp",
    async: false,
    jsonp: "callback",
    jsonpCallback: "success_jsonp",
    data: {
      userId: Uid
    },
    success: function (data) {
      var tpl=document.getElementById("tpl").innerHTML;
      data.responseBody.Uid=Uid;
      var html=juicer(tpl,data.responseBody);
      $("body").html(html);

      /*点击兑换按钮*/
      $(".content-list-border-right-exchange").on("click",  function  ()  {
          if($(this).attr("data-type")  ==  "3"){
          window.location.href  =  "http://wx.pdyulu.com/active/active.aspx?service=027b4329-7db1-4414-bd49-f0f142518df3";
          }
          else{
          var  shopId  =  $(this).closest(".content-list").attr("data-id");
          $.ajax({
              type:  "post",
              url:"/dingding-web/userMallAction!buyItem.action",
              dataType:  "jsonp",
              async:  false,
              jsonp:  "callback",
              jsonpCallback:  "success_jsonp",
              data:  {
                  userId:  Uid,
                  commodityId:  shopId
              },
              success:  function  (data)  {
                  switch  (parseInt(data.code)){
                      case  100:
                          swal({
                              title:  "兑换成功",
                              type:  "warning",
                              confirmButtonColor:  "#DD6B55",
                              confirmButtonText:  "确定"
                          },  function  ()  {
                              window.location.reload();
                          });
                          break;
                      case  202:
                          swal({
                              title:  "余额不足",
                              type:  "warning",
                              confirmButtonColor:  "#DD6B55",
                              confirmButtonText:  "确定"
                          });
                          break;
                      case  203:
                          swal({
                              title:  "商品数量不足",
                              type:  "warning",
                              confirmButtonColor:  "#DD6B55",
                              confirmButtonText:  "确定"
                          });
                          break;
                      case  204:
                          swal({
                              title:  "网络异常",
                              type:  "warning",
                              confirmButtonColor:  "#DD6B55",
                              confirmButtonText:  "确定"
                          });
                          break;
                  }
              }
          });
          }
          return  false;
      });

      /*点击商品列表进入商品详情页*/
      $(".content-list").on("click", function () {
    	  
    	  if($(this).attr("data-id") == '3'){//如果是保养券
    		  window.location.href  =  "http://wx.pdyulu.com/active/active.aspx?service=027b4329-7db1-4414-bd49-f0f142518df3";
    		  return ;
    	  } 
    	  window.location.href = $(this).attr("value");
      })
    }
  });





});
